package com;

import com.zz.mapper.*;
import com.zz.model.Address;
import com.zz.model.Member;
import com.zz.model.Role;
import com.zz.model.User;
import com.zz.mybatis.MybatisUtil;
import org.apache.ibatis.session.SqlSession;
import org.junit.Test;

import java.util.List;
import java.util.Map;

/**
 * Created by Administrator on 2017/1/12.
 */
public class Tttt {
    @Test
    public void oneone() {
        SqlSession s = MybatisUtil.getSession();
        MemberMapper mm = s.getMapper(MemberMapper.class);
        //Member m = mm.queryById(1);
        //System.out.println(m);

        System.out.println(mm.findById(2));


/*
        List<Map<String, Object>> lm = mm.query();
        System.out.println(lm.size());
        for (Map<String, Object> m : lm) {
            System.out.println(m);
        }
        for (Map<String, Object> m : lm) {
            System.out.println(m.get("mname") + "--" + m.get("aname"));
        }

        List<Map<String, Object>> lmo = mm.queryAll();
        System.out.println(lmo.size());
        for (Map<String, Object> m : lmo) {
            System.out.println(m);
        }
        for (Map<String, Object> m : lmo) {
            System.out.println(m.get("mname") + "---" + m.get("aname"));
        }
*/

/*
        AddressMapper am = s.getMapper(AddressMapper.class);
        //System.out.println(am.queryById(102));
        List<Map<String, Object>> ll = am.query();
        for (Map<String, Object> m : ll) {
            System.out.println(m.get("aname"));
            System.out.println(m.get("mname"));
        }
*/

        s.commit();
        s.close();
    }

    @Test
    public void oneMore() {
        SqlSession s = MybatisUtil.getSession();
        UserMapper um = s.getMapper(UserMapper.class);
        RoleMapper rm = s.getMapper(RoleMapper.class);

//        User u = um.queryById(2);
//        List<Role> lr = u.getRoles();
//        for(Role r : lr){
//            System.out.println(r.getName());
//        }
        Role r = rm.queryById(5);
        //System.out.println(r.getId()+"---"+r.getName());
        System.out.println(r.getName());
        System.out.println(r.getUser());
    }


    @Test
    public void order() {
        SqlSession s = MybatisUtil.getSession();
        OrderMapper om = s.getMapper(OrderMapper.class);

        om.save("000007", 539, 4);
        om.save("000808", 9999, 4);

        s.commit();
        s.close();
    }
}
